import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UsersModule } from './users/users.module';
import { PhoneModule } from './phone/phone.module';
import { UploadModule } from './upload/upload.module';
import { AuthModule } from './auth/auth.module';
import { ServeStaticModule } from '@nestjs/serve-static';
import { join } from 'path';
import { PageModule } from './page/page.module';
import { FormModule } from './form/form.module';
import { CooperateModule } from './cooperate/cooperate.module';
import { TokenModule } from './token/token.module';

const ENV = process.env.NODE_ENV;
const dbInfo = {
  host: 'localhost',
  port: 3306,
  username: 'root',
  password: '123456789',
};
if (ENV === 'prod') {
  dbInfo.host = '121.4.15.230' || '106.52.59.214';
  dbInfo.port = 3306 || 25532;
  dbInfo.username = 'zhineng_qusaoma_';
  dbInfo.password = 'kaz35iZZjENM3b2i';
}
const { host, port, username, password } = dbInfo;
console.log('dbInfo', dbInfo);

@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'mysql',
      host,
      port,
      username,
      password,
      database: 'zhineng_qusaoma_',
      entities: [],
      autoLoadEntities: true,
    //   synchronize: true,
    }),
    UsersModule,
    PhoneModule,
    UploadModule,
    AuthModule,
    PageModule,
    FormModule,
    CooperateModule,
    TokenModule,
    ServeStaticModule.forRoot(
      {
        rootPath: join(__dirname, '..', 'admin'),
        serveRoot: '/admin',
      },
      {
        rootPath: join(__dirname, '..', 'public'),
        serveRoot: '/public',
      },
      {
        rootPath: join(__dirname, '..', 'root'),
        serveRoot: '/',
      },
    ),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
